from data_preparation.trajectory import Trajectory
from data_preparation.trajectory_set import TrajectorySet
from tools.data_reader import DataReader
from config.parameter_carrier import ParameterCarrier


class DataPreparer:

    def __init__(self, args):
        self.cc = ParameterCarrier(args)

    def get_trajectory_set(self):
        tr_set = TrajectorySet()
        reader1 = DataReader()
        tr_list = reader1.read_trajectories_from_data_file(self.cc.dataset_file_name)
        tr_total_length = 0
        tr_length_list = []
        print("轨迹数量:", len(tr_list))

        for tr_array in tr_list:
            tr_total_length += len(tr_array)
            tr_length_list.append(len(tr_array))
        tr_length_temp = 0
        tr_length_list.sort()

        for i in range(tr_total_length):
            tr_length_temp += tr_length_list[i]
            if tr_length_temp >= tr_total_length * 0.8:
                tr_set.lmax = tr_length_list[i]
                break

        for tr_array in tr_list:
            tr = Trajectory()
            # if len(tr_array) > tr_set.lmax:
            #     tr.real_point_trajectory = tr_array[:tr_set.lmax]
            # else:
            #     tr.real_point_trajectory = tr_array
            tr.real_point_trajectory = tr_array
            tr_set.add_trajectory(tr)
        return tr_set
